/*
Philip Dilse
dilsep
Assignment 3

unit test for village card
*/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "dominion.h"
#include "dominion_helpers.h"

int main() {
    int i;
    int handCount;
    int startHandCount = 1;
    int maxHandCount = 50;
    int numActions;
    int player = 0;
    int handPos;
    int numCurses;

    struct gameState *gs = newGame();

    gs->whoseTurn = player; 
    // set up random number gen
    srand(time(NULL));

    for (handCount = startHandCount; handCount <= maxHandCount; handCount++) {
        gs->handCount[player] = handCount;
        numCurses = 0;

        //initialize hand to all curses (could be anything)
        for (i = 0; i < handCount; i++) {
            gs->hand[player][i] = curse;
        }

        //initialize deck count
        gs->deckCount[player] = 5;
        for (i = 0; i < 5; i++) {
            gs->deck[player][i] = gold;
        }

        //randomly pick handPos and swap in village
        handPos = rand() % handCount;
        gs->hand[player][handPos] = village;

        // randomly set actions to be between 1 and 10
        numActions = (rand() % 10) + 1;
        gs->numActions = numActions;

        cardEffect(village, 0, 0, 0, gs, handPos, &i);

        // verify numActions two more than before
        if (numActions + 2 != gs->numActions) {
            printf("village_effect() error: numActions before=%d after=%d\n", numActions, gs->numActions);
        }
    
        // handCount should be the same
        if (handCount != gs->handCount[player]) {
            printf("village_effect() error: handCount before=%d after=%d\n", handCount, gs->handCount[player]);
        }

        // should be handCount - 1 curse cards in hand
        for (i = 0; i < gs->handCount[player]; i++) {
            if (gs->hand[player][i] == curse) {
                numCurses++;
            }
        }        

        if (numCurses != handCount - 1) {
            printf("village_effect() error: numCurses=%d handCount=%d\n", numCurses, handCount);
        }   
    }
    free(gs);
    return 0;
}
